package testAndSomeTries.videoCapture;

import java.util.Vector;

import javax.media.Buffer;
import javax.media.CaptureDeviceInfo;
import javax.media.CaptureDeviceManager;
import javax.media.Format;
import javax.media.Manager;
import javax.media.control.FormatControl;
import javax.media.format.VideoFormat;
import javax.media.protocol.CaptureDevice;
import javax.media.protocol.DataSource;
import javax.media.util.BufferToImage;

public class FrameCatching {
	private Buffer _buf;
	private BufferToImage _b2i;
	private CaptureDeviceInfo _webcam;
	private DataSource _data;
	private VideoFormat _format;
	// we will need other stuff here ...
	
	
	//constructors ***********************************************
	public FrameCatching(VideoFormat format) throws Exception{
		_format = format;
		Vector deviceList = CaptureDeviceManager.getDeviceList(format);
		if (!deviceList.isEmpty()){
			throw new Exception("given format does not match any aviable one");
		}
		_webcam = (CaptureDeviceInfo)deviceList.firstElement();
		//could launch Exception (IO or NoDataSource) but not visible here because of the ugly throws Exception upstairs
		_data = Manager.createDataSource(_webcam.getLocator());
		_buf = new Buffer();
		_b2i = new BufferToImage((VideoFormat)_buf.getFormat());
		//here we are suppose to check for a good format to the snapshot
		//but I'll just take one which fit well
		FormatControl[] aviableFormatControls = ((CaptureDevice) _webcam).getFormatControls();
		Format oneAviableFormat = aviableFormatControls[0].getFormat();
		
	}
	
}
